package bridge

import (
	"fmt"
	"io"
)

type JsonExporter struct {
	mFetcher IDataFetcher
}

func NewJsonExporter(fetcher IDataFetcher) IDataExporter {
	return &JsonExporter{
		fetcher,
	}
}

func (me *JsonExporter) Fetcher(fetcher IDataFetcher) {
	me.mFetcher = fetcher
}

func (me *JsonExporter) Export(sql string, writer io.Writer) error {
	rows := me.mFetcher.Fetch(sql)
	fmt.Printf("JsonExporter.Export, got %v rows\n", len(rows))
	for i,it := range rows {
		fmt.Printf("  %v %s\n", i + 1, it.FieldsString())
	}
	return nil
}
